<?php 
  if(!(isset($_GET['tid'])||isset($_GET['pid'])))
     header("Location: index.php");
  
  require_once 'lib/HTML/Util.php';
  require_once 'lib/HTML/LinkLoader.php';
  require_once 'lib/HTML/FormElements.php';  
  require_once 'controllers/Track.php';
     
  $track = new Track(array(id=>$_GET['tid']));
  try{$track->getFull();}
  catch(MTException $e){
  	die($e->getMessage());
  }

  if($track->result() == null)
      header("Location: /track/listen/notfound");
  
  $date = preg_split('(-|:|\s)',$track->result()->time_added,6);
  //print_r($date);
  $time_added = date("M dS, Y", mktime(0, 0, 0, (int)$date[1], (int)$date[2], (int)$date[0]));
  
  $ll = new LinkLoader();
  $ll->loadCSS(array('listen.css','tabs.css'));
  // JavaScript loader  
  $ll->loadJs(array('Ajax.js','WebServices/WebService.js',
                    'WebServices/MusicBrainz.js','Components/Track.js',
                    'Components/Article.js','MusicTalk.js','Tabs.js','WebServices/YouTubeVids.js','lib/swfobject.js','Player.js'));
  $ll->loadJs('js.js','views/track/listen/');
  
  //the song informations
  $smarty->assign_by_ref("track_info",$track->result());
  $smarty->assign('time_added', $time_added);
  $smarty->assign("title", "Listen to: ".$track->result()->title);
  $smarty->assign_by_ref("ll", $ll);
  $smarty->assign_by_ref("html",new Util());
  $smarty->assign_by_ref("fe",new FormElements());
  
  $smarty->display("head.tpl");
  $smarty->display("nav.tpl");
  // main content
  $smarty->display("../track/listen/view.tpl");
  
  $smarty->display("footer.tpl");
?>

    
    
